﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.components.mainmenu {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.external.*;
    import flash.display.*;
    import reprise.controls.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class ShopItemDisplay extends reprise.controls.SimpleButton {

        private const HIGHLIGHT_ANIMATION_LINKAGE_ID:String = "HighlightCustomizeIcon";
        private const HIGHLIGHT_ANIMATION_END_FRAME_LABEL:String = "end";

        protected var _type:String;
        protected var _destination:String;
        protected var _cash:int;
        protected var _coins:int;
        protected var _giftable:Boolean;
        protected var _count:int;
        protected var _hasQuestionMark:Boolean;
        protected var _countLabel:Label;
        protected var _isNewLabel:String;
        protected var _isLockedDisplay:UIComponent;
        protected var _iconDisplay:UIComponent;
        protected var _icon:MovieClip;
        protected var _isLocked:Boolean;
        protected var _highlightDisplay:UIComponent;
        protected var _highlightMovieClip:MovieClip;
        protected var _assetURL:String;
        private var _loaderAnimation:MovieClip;

        public function ShopItemDisplay(_arg1:String, _arg2:String, _arg3:String, _arg4:int, _arg5:int, _arg6:int, _arg7:Boolean, _arg8:String, _arg9:Boolean){
            this._type = _arg1;
            this._assetURL = _arg2;
            this._destination = _arg3;
            this._cash = _arg4;
            this._coins = _arg5;
            this._count = _arg6;
            this._isNewLabel = _arg8;
            this._hasQuestionMark = _arg9;
            this._isLocked = _arg7;
        }
        override public function remove(... _args):void{
            if (this._icon){
                this._icon.removeEventListener(MouseEvent.MOUSE_OVER, this.icon_mouseOver);
                this._icon.removeEventListener(MouseEvent.MOUSE_OUT, this.icon_mouseOut);
            };
            super.remove();
        }
        public function get type():String{
            return (this._type);
        }
        public function get destination():String{
            return (this._destination);
        }
        public function set count(_arg1:int):void{
            this._count = _arg1;
            this.updateCountLabel();
        }
        public function setLocked(_arg1:Boolean):void{
            if (_arg1 == this._isLocked){
                return;
            };
            this._isLocked = _arg1;
            if (_arg1){
                this._isLockedDisplay.addCSSClass("isLocked");
            } else {
                this._isLockedDisplay.removeCSSClass("isLocked");
            };
        }
        public function playHighlight():void{
            if (!this._isLocked){
                this._highlightMovieClip = AssetsLibrary.getMovieClip(this.HIGHLIGHT_ANIMATION_LINKAGE_ID);
                this._highlightDisplay.addChild(this._highlightMovieClip);
                this._highlightMovieClip.addEventListener(Event.ENTER_FRAME, this.highlightMovieClip_enterFrame);
            };
        }
        private function highlightMovieClip_enterFrame(_arg1:Event):void{
            if (((this._highlightMovieClip) && ((this._highlightMovieClip.currentFrameLabel == this.HIGHLIGHT_ANIMATION_END_FRAME_LABEL)))){
                this._highlightMovieClip.removeEventListener(Event.ENTER_FRAME, this.highlightMovieClip_enterFrame);
                this._highlightMovieClip.stop();
                this._highlightDisplay.removeChild(this._highlightMovieClip);
                this._highlightMovieClip = null;
            };
        }
        override protected function initialize():void{
            addCSSClass("customizeItem");
            addCSSClass("myriadProFont");
            super.initialize();
        }
        override protected function createChildren():void{
            this._iconDisplay = addComponent("iconDisplay");
            this._loaderAnimation = AssetsLibrary.getMovieClip("SmallLoader");
            this._loaderAnimation.x = (this._loaderAnimation.y = 15);
            this._iconDisplay.addChild(this._loaderAnimation);
            this.loadAsset();
            this.createCashOrCoinsLabel();
            ((this._hasQuestionMark) && (addComponent("questionMark")));
            this._isLockedDisplay = addComponent("lockedDisplay");
            this._countLabel = Label(addComponent("countLabel", null, Label));
            this.updateCountLabel();
            this._highlightDisplay = addComponent("highlightDisplay");
            this.setLocked(this._isLocked);
        }
        private function loadAsset():void{
            var _local1:ImageResource;
            if (!this._icon){
                _local1 = new ImageResource(this._assetURL);
                _local1.addEventListener(Event.COMPLETE, this.assetResource_complete);
                _local1.execute();
            };
        }
        private function assetResource_complete(_arg1:Event):void{
            this.createIcon();
        }
        private function createIcon():void{
            this._iconDisplay.removeChild(this._loaderAnimation);
            this._loaderAnimation.stop();
            this._loaderAnimation = null;
            this._icon = AssetsLibrary.getMovieClip((GameConstants.CUSTOMIZE_ICON_PREFIX + this._type));
            this.addIcon();
        }
        private function addIcon():void{
            if (!this._icon){
                return;
            };
            this._icon.mouseChildren = false;
            this._icon.cacheAsBitmap = true;
            this._icon.stop();
            this._icon.addEventListener(MouseEvent.MOUSE_OVER, this.icon_mouseOver);
            this._icon.addEventListener(MouseEvent.MOUSE_OUT, this.icon_mouseOut);
            this._iconDisplay.addChild(this._icon);
        }
        private function createCashOrCoinsLabel():void{
            var _local3:Label;
            var _local1:UIComponent = addComponent("cashDisplay");
            var _local2:Label = Label(_local1.addComponent("cashLabel", null, Label));
            _local1.mouseChildren = false;
            _local1.mouseEnabled = false;
            if (this._cash > 0){
                _local2.setLabel(String(this._cash));
                _local2.addCSSClass("woogaCash");
            } else {
                _local2.setLabel(String(this._coins));
            };
            if (this._isNewLabel != ""){
                _local3 = Label(addComponent("isNewLabel", null, Label));
                _local3.setLabel(this._isNewLabel);
            };
        }
        private function updateCountLabel():void{
            if (this._count > 0){
                this._countLabel.show();
            } else {
                this._countLabel.hide();
            };
            this._countLabel.setLabel(String(this._count));
        }
        private function icon_mouseOut(_arg1:MouseEvent):void{
            var _local2:MovieClip = MovieClip(_arg1.target);
            _local2.gotoAndStop("default");
        }
        private function icon_mouseOver(_arg1:MouseEvent):void{
            var _local2:MovieClip = MovieClip(_arg1.target);
            _local2.gotoAndStop("hover");
        }

    }
}//package net.wooga.pets.views.components.mainmenu 
